//	ID : pallab81
// 	PROG : 336
// 	LANG : C++
// 	2011-07-07-08.57.36 Thursday
//
// 	"I have not failed, I have just found 10000 ways that won't work.
//


#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>

#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>

using namespace std;

#define fo(i,ed) for( int i = 0; i < ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define mk make_pair
#define pb push_back
#define f first
#define s second
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()

int n_node;
int cases;
set< int > vis;
map< int ,vector<int> > path;

inline void read() {
    path.clear();
    fo(i,n_node) {
        int x,y;
        scanf("%d %d",&x,&y);
        path[x].pb( y );
        path[y].pb( x );
    }
}
inline void bfs( int source, int ttl) {
    queue< pair<int,int> >q;
    vis.clear();

    int total = SZ( path );
    q.push( mk(source,ttl) );
    vis.insert( source );

    while( q.empty()==false ) {
        pair< int,int > peak = q.front();
        q.pop();
        vector< int > _path = path[peak.f];
        for(int i=0; i< SZ(_path); ++i ) {
            int sink = _path[i];
            if( peak.s-1 >=0 ) {
                if( vis.count(sink)<1 ) {
                    vis.insert( sink );
                    q.push( mk(sink, peak.s-1) );
                }
            }
        }
    }
    printf("Case %d: %d nodes not reachable from node %d with TTL = %d.\n",cases,
           total-SZ(vis),source,ttl);
}
inline void query() {
    int source,ttl;
    while( scanf("%d %d",&source,&ttl) ) {
        if(source==0 && ttl==0)break;
        ++cases;
        bfs( source, ttl);
    }
}
inline void doit() {
    read();
    query();
}

int main() {
    cases=0;
    while( scanf("%d",&n_node)==1 ) {
        if( n_node==0 )break;
        doit();
    }

    return 0;
}

